using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.Specialized;
using Instedd.Labs.Geo.Library.Kml;

namespace Instedd.Labs.Geo.Library.Sms
{
    public class Configuration
    {
        private string senderNameLookupPath = @"SenderNameLookupTable.csv";

        public string SenderNameLookupPath
        {
            get { return senderNameLookupPath; }
            set { senderNameLookupPath = value; }
        }

        private string kmlOutput = "KML";

        public string KmlOutput
        {
            get { return kmlOutput; }
            set { kmlOutput = value; }
        }

        private string rssOutput = "RSS";

        public string RssOutput
        {
            get { return rssOutput; }
            set { rssOutput = value; }
        }

        private string localNumber;

        public string LocalNumber
        {
            get { return localNumber; }
            set { localNumber = value; }
        }

        public void Load(NameValueCollection values)
        {
            Guard.ArgumentNotNull(values, "configurationStore");

            this.senderNameLookupPath = PathResolver.TryToResolveUsingDataDirectory(TryGetValue(values, "SenderNameLookupPath", senderNameLookupPath));
            this.kmlOutput = PathResolver.TryToResolveUsingBaseDirectory(TryGetValue(values, "KmlOutput", senderNameLookupPath));
            this.rssOutput = PathResolver.TryToResolveUsingBaseDirectory(TryGetValue(values, "RssOutput", senderNameLookupPath));
            this.defaultLocation = TryGetValue(values, "DefaultLocation", "37.477719*-122.150593");
            
            this.localNumber = values["LocalNumber"];
        }

        public string TryGetValue(NameValueCollection values, string key, string defaultValue)
        {
            string value = values[key];

            return string.IsNullOrEmpty(value) ? defaultValue : value;
        }

        private string defaultLocation;

        public string DefaultLocation
        {
            get { return defaultLocation; }
            set { defaultLocation = value; }
        }
    }
}